-- wrk性能测试脚本

-- 初始化
init = function(args)
   requests = 0
   responses = 0
end

-- 请求前处理
request = function()
   requests = requests + 1
   headers["Content-Type"] = "application/json"
   headers["User-Agent"] = "BugSeeker-Perf-Test/1.0"
   return wrk.format("GET", "/api/health")
end

-- 响应处理
response = function(status, headers, body)
   responses = responses + 1
   if status ~= 200 then
      print("Error response: " .. status)
   end
end

-- 测试结束处理
done = function(summary, latency, requests)
   io.write("------------------------------\n")
   io.write("Performance Test Results\n")
   io.write("------------------------------\n")
   io.write("Requests: " .. requests .. "\n")
   io.write("Duration: " .. summary.duration/1000000 .. "s\n")
   io.write("Data Read: " .. summary.bytes .. " bytes\n")
   io.write("Requests/sec: " .. summary.requests/summary.duration*1000000 .. "\n")
   io.write("Transfer/sec: " .. summary.bytes/summary.duration*1000000 .. " bytes/sec\n")
   io.write("------------------------------\n")
end